<?php
/**
 * 跃飞科技版权所有 @2017
 * User: 钟贵廷
 * Date: 2017/5/22
 * Time: 17:18
 */

namespace app\admin\controller;
use think\Loader;
use think\Request;

class Config extends Admin
{
    public function save()
    {
        if(Request::instance()->isPost())
        {
             $validate = Loader::validate('Config');
             if($validate->check($_POST))
             {
                $model = new \app\admin\model\Config();
                $model->save(['value'=>$_POST['appId'],'add_time'=>time()],['key'=>'appId']);
                $model->save(['value'=>$_POST['appSecret'],'add_time'=>time()],['key'=>'appSecret']);
                $model->save(['add_time'=>0],['key'=>'access_token']);
                $this->success('更新成功');
             }
            else
            {
                $this->error($validate->getError());
            }
        }

        $model = model('Config');
        $data = $model->select()->toArray();
        foreach ($data as $k=>$v)
        {
            $this->assign($v['key'],$v['value']);
        }
        return $this->fetch();
    }
}